<template>
    <el-dialog title="Add Course" :close-on-click-modal="false" :visible.sync="visible">
        <el-form :model="dataForm" ref="dataForm" label-width="80px">
            <el-form-item label="semester">
                <el-select v-model="dataForm.schoolTerm" placeholder="Please select the semester">
                    <el-option label="First semester" :value=1></el-option>
                    <el-option label="Second semester" :value=2></el-option>
                    <el-option label="The third semester" :value=3></el-option>
                    <el-option label="The fourth semester" :value=4></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="major">
                <el-input v-model="dataForm.subject" placeholder="Fill in the professional name"></el-input>
            </el-form-item>
            <el-form-item label="Course name">
                <el-input v-model="dataForm.courseName" placeholder="Fill in the course name"></el-input>
            </el-form-item>
            <el-form-item label="Course location">
                <el-input v-model="dataForm.courseAddress" placeholder="Fill in the class location"></el-input>
            </el-form-item>
            <el-form-item label="section">
                <el-select v-model="dataForm.classSection" placeholder="Please select the section">
                    <el-option label="Section I" :value=1></el-option>
                    <el-option label="Section II" :value=2></el-option>
                    <el-option label="Section III" :value=3></el-option>
                    <el-option label="Section IV" :value=4></el-option>
                    <el-option label="Section V" :value=5></el-option>
                    <el-option label="Section VI" :value=6></el-option>
                    <el-option label="Section VII" :value=7></el-option>
                    <el-option label="Section VIII" :value=8></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="week">
                <el-select v-model="dataForm.week" placeholder="Please select the week">
                    <el-option label="Monday" :value=1></el-option>
                    <el-option label="Tuesday" :value=2></el-option>
                    <el-option label="Wednesday" :value=3></el-option>
                    <el-option label="Thursday" :value=4></el-option>
                    <el-option label="Friday" :value=5></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">Add Now</el-button>
                <el-button @click="visible = false">cancel</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          courseName: '',
          courseAddress: '',
          classSection: '',
          week: '',
          subject: '',
          schoolTerm: ''
        }
      }
    },
    methods: {
      init () {
        console.log('123456')
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          this['dataForm'] = {}
        })
      },
      onSubmit () {
        console.log(this.dataForm)
        this.$http({
          url: this.$http.adornUrl(`/edu/course/addCourse`),
          method: 'post',
          data: this.dataForm
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.$message({
              message: 'success',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.visible = false
                this.$emit('refreshDataList')
              }
            })
          } else {
            this.$message.error(data.msg)
          }
        })
      }
    }
  }
</script>